package UIComponent 
{
	import fl.controls.UIScrollBar;
	import flash.display.Sprite;
	import flash.events.TextEvent;
	
	/**
	 * ...
	 * @author gcxk721
	 */
	public class CustomUIScrollBar extends Sprite 
	{
		
		public var textField:CustomTextfield = null;
        private var upArrowBg:Sprite = null;
        private var _autoRemoveUIBarWidth:Boolean;
        private var UIBar:UIScrollBar = null;
        private var color:uint = 0;
        private var h:Number = 0;
        private var w:Number = 0;
        private var direction:String = "";
		
		public function CustomUIScrollBar(_w : Number, _h:Number, _direction : String = "right", _color : int = 0xfff1d9)
		{
            super();
            this.w = _w;
            this.h = _h;
            this.color = _color;
            this.textField = new CustomTextfield();
            this.textField.height = this.h;
            this.textField.width = this.w;
            this.textField.wordWrap = true;
            this.textField.border = false;
            this.textField.textColor = this.color;
            this.textField.doubleClickEnabled = false;
            this.textField.addEventListener(TextEvent.LINK, this.onLink);
            this.UIBar = new UIScrollBar();
            this.UIBar.scrollTarget = this.textField;
            this.UIBar.setSize(19, this.h);
            this.UIBar.visible = false;
            try 
			{
                this.upArrowBg = Reflection.createInstance(("compS_MC_ScrollPaneBgSkin" + 3));
            } 
			catch (e:Error) 
			{
                upArrowBg = new Sprite();
            }
            this.upArrowBg.width = 19;
            this.upArrowBg.height = 19;
            this.upArrowBg.y = 19;
            this.skin = 2;
            if (_direction == null)
			{
                this.direction = "right";
            } 
			else 
			{
                this.direction = _direction;
            }
            if (this.direction == "right")
			{
                this.UIBar.move(this.textField.x + this.textField.width, 0);
                this.upArrowBg.x = this.UIBar.x;
            } 
			else 
			{
                this.textField.x = this.UIBar.width;
            }
            addChildAt(this.upArrowBg, 0);
            this.upArrowBg.visible = false;
            addChild(this.textField);
            addChild(this.UIBar);
        }
		
        public function set textFieldHeight(_h : int):void
		{
            this.h = _h;
            this.textField.height = this.h;
            this.UIBar.setSize(19, _h);
        }
		
        public function setupArrowBgVisible(value : Boolean):void
		{
            this.upArrowBg.visible = value;
        }
		
        private function drawItemBG(_arg1:int, _arg2:int, _arg3:int, _arg4:int):void
		{
            var _local5:Shape = new Shape();
            _local5.x = _arg3;
            _local5.y = _arg4;
            addChildAt(_local5, 0);
            var _local6:Graphics = _local5.graphics;
            _local6.beginFill(329225);
            _local6.drawRoundRect(0, 0, _arg1, _arg2, 7, 7);
            _local6.endFill();
            _local6.beginFill(6711395);
            _local6.drawRoundRect(1, 1, (_arg1 - 2), (_arg2 - 2), 7, 7);
            _local6.endFill();
            _local6.beginFill(592658);
            _local6.drawRoundRect(2, 2, (_arg1 - 4), (_arg2 - 4), 7, 7);
            _local6.endFill();
        }
		
        public function set textFormat(_arg1:TextFormat):void
		{
            this.textField.setTextFormat(_arg1, 0, this.text.length);
        }
		
        public function get autoRemoveUIBarWidth():Boolean{
            return (this._autoRemoveUIBarWidth);
        }
        private function onScroll(_arg1:Event):void{
            this.checkScrollState();
        }
        private function setSkin(_arg1:String, _arg2:String):void{
            var styleName:* = _arg1;
            var className:* = _arg2;
            try {
                this.UIBar.setStyle(styleName, Reflection.getClass(className));
            } catch(e:Error) {
                debug(("加载皮肤失败，" + e.message));
            };
        }
        public function destroy():void{
            if (this.textField != null){
                this.textField.removeEventListener(TextEvent.LINK, this.onLink);
                this.textField.removeEventListener(Event.SCROLL, this.onScroll);
                this.textField.filters = null;
                this.textField = null;
            };
        }
        override public function get width():Number{
            return (this.w);
        }
        private function checkScrollState():void{
            if (this.textField.maxScrollV > 1){
                this.UIBar.visible = true;
            } else {
                this.UIBar.visible = false;
            };
        }
        public function set text(_arg1:String):void{
            if (_arg1 != null){
                this.textField.text = _arg1;
                this.UIBar.update();
                this.checkScrollState();
                this.checkUIBarWidth();
                this.upArrowBg.height = (this.h - 38);
                if (this.textField.textHeight >= this.height){
                    this.upArrowBg.visible = true;
                } else {
                    this.upArrowBg.visible = false;
                };
            };
        }
        override public function get height():Number{
            return (this.h);
        }
        public function get text():String{
            return (this.textField.text);
        }
        private function checkUIBarWidth():void{
            if (this._autoRemoveUIBarWidth){
                if (this.UIBar.visible == true){
                    this.textField.width = this.w;
                } else {
                    this.textField.width = (this.w + this.UIBar.width);
                };
            };
        }
        public function set htmlText(_arg1:String):void{
            if (_arg1 != null){
                this.textField.htmlText = _arg1;
                this.UIBar.update();
                this.checkScrollState();
                this.checkUIBarWidth();
                this.upArrowBg.height = (this.h - 38);
                if (this.textField.textHeight >= this.height){
                    this.upArrowBg.visible = true;
                } else {
                    this.upArrowBg.visible = false;
                };
            };
        }
        public function removeGlow():void{
            this.textField.filters = [];
        }
        public function set type(_arg1:String):void{
            this.textField.type = _arg1;
            if (_arg1 == TextFieldType.INPUT){
                this.textField.addEventListener(Event.SCROLL, this.onScroll);
            };
        }
        public function get htmlText():String{
            return (this.textField.htmlText);
        }
		
        private function onLink(evt : TextEvent):void
		{
            evt.stopImmediatePropagation();
            evt.stopPropagation();
            dispatchEvent(evt);
        }
		
        public function set skin(_arg1:uint):void{
            if (_arg1 > 0){
                this.setSkin("upArrowUpSkin", ("compS_MC_ArrowUp_upSkin" + 3));
                this.setSkin("upArrowOverSkin", ("compS_MC_ArrowUp_overSkin" + 3));
                this.setSkin("upArrowDownSkin", ("compS_MC_ArrowUp_downSkin" + 3));
                this.setSkin("upArrowDisabledSkin", ("compS_MC_ArrowUp_disabledSkin" + 3));
                this.setSkin("trackUpSkin", ("compS_MC_Track_skin" + 3));
                this.setSkin("trackOverSkin", ("compS_MC_Track_skin" + 3));
                this.setSkin("trackDownSkin", ("compS_MC_Track_skin" + 3));
                this.setSkin("trackDisabledSkin", ("compS_MC_Track_skin" + 3));
                this.setSkin("thumbUpSkin", ("compS_MC_Thumb_upSkin" + 3));
                this.setSkin("thumbOverSkin", ("compS_MC_Thumb_overSkin" + 3));
                this.setSkin("thumbIcon", ("compS_MC_Bar_thumbIcon" + 3));
                this.setSkin("thumbDownSkin", ("compS_MC_Thumb_downSkin" + 3));
                this.setSkin("downArrowUpSkin", ("compS_MC_ArrowDown_upSkin" + 3));
                this.setSkin("downArrowOverSkin", ("compS_MC_ArrowDown_overSkin" + 3));
                this.setSkin("downArrowDownSkin", ("compS_MC_ArrowDown_downSkin" + 3));
                this.setSkin("downArrowDisabledSkin", ("compS_MC_ArrowDown_disabledSkin" + 3));
            };
        }
        public function set autoRemoveUIBarWidth(_arg1:Boolean):void{
            this._autoRemoveUIBarWidth = _arg1;
        }
        public function addBorder():void{
            this.drawItemBG(((this.w + this.UIBar.width) + 6), (this.h + 6), (this.textField.x - 3), (this.textField.y - 3));
        }
		
	}

}